home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / adasmall / test5.ada < prev    next >
Text File  |  1996-01-30  |  4KB  |  156 lines

  1. with SMALL_SP; use SMALL_SP;
  2. procedure TEST5 is
  3.  
  4.   -------------------------------------------------------------------------
  5.   -- This program demonstrates the Timed and Conditional entry calling   --
  6.   -- and the Selective Wait capability of SmallAda v2.0.  
  7.   -------------------------------------------------------------------------
  8.  
  9.   SCREEN : SEMAPHORE;
  10.  
  11.   task R is
  12.     entry E1( CALLER : in character; D : in float);
  13.     entry E2( CALLER : in character; D : in float);
  14.     entry E3( CALLER : in character; D : in float);
  15.   end R;
  16.  
  17.   task A;
  18.   task B;
  19.   task C;
  20.  
  21.   task body R is
  22.     C : character;
  23.     DT : float;
  24.   begin
  25.     INHERITP(true);
  26.     WAIT(SCREEN);
  27.     CURSORAT(2,1); Put("Task R receives calls from A, B, C on E1, E2, E3.");
  28.     SIGNAL(SCREEN);
  29.     loop
  30.       select
  31.         accept E1(CALLER : in character; D : in float) do
  32.           C := CALLER;
  33.           DT := D;
  34.         end E1;
  35.         WAIT(SCREEN);
  36.         CURSORAT(3,1); Put("===> R.E1 called by "); Put(C);
  37.         SIGNAL(SCREEN);
  38.         delay DT;
  39.       or
  40.         accept E2(CALLER : in character; D : in float) do
  41.           C := CALLER;
  42.           DT := D;
  43.         end E2;
  44.         WAIT(SCREEN);
  45.         CURSORAT(3,1); Put("===> R.E2 called by "); Put(C);
  46.         SIGNAL(SCREEN);
  47.         delay DT;
  48.       or
  49.         accept E3(CALLER : in character; D : in float) do
  50.           C := CALLER;
  51.           DT := D;
  52.         end E3;
  53.         WAIT(SCREEN);
  54.         CURSORAT(3,1); Put("===> R.E3 called by "); Put(C);
  55.         SIGNAL(SCREEN);
  56.         delay DT;
  57.       or
  58.         delay 1.0;
  59.         WAIT(SCREEN);
  60.         CURSORAT(3,1); Put("===> Timed Out Waiting     ");
  61.         SIGNAL(SCREEN);
  62.         delay 3.0;
  63.       or
  64.         delay 100000.0; -- If this delay is chosen the system will hang
  65.         -- for a while
  66.       end select;
  67.       WAIT(SCREEN);
  68.       CURSORAT(3,1); Put("===>                   ");
  69.       SIGNAL(SCREEN);
  70.     end loop;
  71.     accept E2;
  72.   end R;
  73.  
  74.   task body A is
  75.   begin
  76.     WAIT(SCREEN);
  77.     CURSORAT(5,1); Put("Task A does timed calls to R.E1");
  78.     SIGNAL(SCREEN);
  79.     loop
  80.       WAIT(SCREEN);
  81.       CURSORAT(6,1); Put("===> calling ....");
  82.       SIGNAL(SCREEN);
  83.       select
  84.         R.E1('A',1.11);
  85.         WAIT(SCREEN);
  86.         CURSORAT(6,1); Put("===> accepted    ");
  87.         SIGNAL(SCREEN);
  88.         delay 1.11;
  89.       or
  90.         delay 2.0;
  91.       end select;
  92.       WAIT(SCREEN);
  93.       CURSORAT(6,1); Put("===> delayed     ");
  94.       SIGNAL(SCREEN);
  95.       delay 3.0;
  96.     end loop;
  97.   end A;
  98.  
  99.   task body B is
  100.   begin
  101.     WAIT(SCREEN);
  102.     CURSORAT(8,1); Put("Task B does conditional calls to R.E2");
  103.     SIGNAL(SCREEN);
  104.     loop
  105.       WAIT(SCREEN);
  106.       CURSORAT(9,1); Put("===> calling ....");
  107.       SIGNAL(SCREEN);
  108.       select
  109.         R.E2('B',0.5);
  110.         WAIT(SCREEN);
  111.         CURSORAT(9,1); Put("===> accepted    ");
  112.         SIGNAL(SCREEN);
  113.         delay 0.5;
  114.       else
  115.         WAIT(SCREEN);
  116.         CURSORAT(9,1); Put("===> **failed**  ");
  117.         SIGNAL(SCREEN);
  118.         delay 0.5;
  119.       end select;
  120.       WAIT(SCREEN);
  121.       CURSORAT(9,1); Put("===> delayed     ");
  122.       SIGNAL(SCREEN);
  123.       delay 0.5;
  124.     end loop;
  125.   end B;
  126.  
  127.   task body C is
  128.   begin
  129.     Priority(100);
  130.     WAIT(SCREEN);
  131.     CURSORAT(11,1); Put("Task C makes calls with high priority to R.E3");
  132.     SIGNAL(SCREEN);
  133.     loop
  134.       WAIT(SCREEN);
  135.       CURSORAT(12,1); Put("===> calling ....");
  136.       SIGNAL(SCREEN);
  137.       select
  138.         R.E3('C',4.0);
  139.         WAIT(SCREEN);
  140.         CURSORAT(12,1); Put("===> accepted    ");
  141.         SIGNAL(SCREEN);
  142.         delay 100.0 * 0.04;
  143.       or
  144.         delay 2.0;
  145.       end select;
  146.       WAIT(SCREEN);
  147.       CURSORAT(12,1); Put("===> delayed     ");
  148.       SIGNAL(SCREEN);
  149.       delay 5.0;
  150.     end loop;
  151.   end C;
  152.  
  153. begin
  154.   SCREEN := 1;
  155. end TEST5;
  156.